package com.yunti.yntk.util;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.NumberFormat;

public class NumberUtils {
    private static  NumberFormat nf = NumberFormat.getInstance();
    static {
        nf.setMaximumFractionDigits(3);
    }

    public static boolean numisnull(double a){
        return Double.isNaN(a);
    }

    public static double numformat(double num,int digit){
        nf.setMaximumFractionDigits(digit);
        return Double.parseDouble(nf.format(num));
    }

    public static double numformat(double num) {
        BigDecimal number = new BigDecimal(num + "");
        BigDecimal result = number.setScale(3, RoundingMode.DOWN); // 舍去第三位小数
        return result.doubleValue();
    }

    public static double numformat2(double num) {
        BigDecimal number = new BigDecimal(num + "");
        BigDecimal result = number.setScale(2, RoundingMode.DOWN); // 舍去第三位小数
        return result.doubleValue();
    }
}
